// 3.5 hours of coding!!!

#include <iostream>
#include <map>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> dict;
string x[100];
vector<string> xx[100];	// list of word that can match x[i];

string origin;

int n, m;
int found;

string empty;

string attempt(int k, string status)
{
//	cerr << status << endl;

	if (k == m)
	{
		found = 1;
		return status;
	}

	for (int i = 0; i < (int) xx[k].size(); i++)
	{
		string s = xx[k][i];

		bool ok = true;
		for (int j = 0; j < (int) s.size(); j++)
			if (status[x[k][j]-'a'] == '*')
			{
				for (int r = 0; r < 26; r++)
					if (status[r] == s[j])
					{
						ok = false;
						break;
					}
				if (!ok) break;
			}
			else 
				if (status[x[k][j]-'a'] != s[j])
				{
					ok = false;
					break;
				}
		if (!ok) continue;

		string newStatus = status;
		for (int j = 0; j < (int) s.size(); j++)
			if (newStatus[x[k][j]-'a'] == '*') newStatus[x[k][j]-'a'] = s[j];

		string b = attempt(k+1, newStatus);
		if (found == 1) return b;
	}

	return empty;
}

bool matched(string a, string b)
{
//	cerr << "Try " << a << " " << b << endl;

	if (a.size() != b.size()) return false;

	char mm[26];
	for (int i = 0; i < 26; i++) mm[i] = '*';

	for (int i = 0; i < (int) a.size(); i++)
		if (mm[a[i]-'a'] == '*')
		{
			for (int j = 0; j < 26; j++)
				if (mm[j] == b[i]) return false;

			mm[a[i]-'a'] = b[i];
		}
		else
			if (mm[a[i]-'a'] != b[i]) return false;

	return true;

}

int main()
{
	scanf("%d\n", &n);
	
	dict.clear();
	for (int i = 0; i < n; i++) 
	{
		char c[100];
		scanf("%s\n", c);
		dict.push_back(string(c));
	}

	for (int i = 0; i < 26; i++) empty += "*";

	string s;
	while (getline(cin, s))
	{
		origin = s;
		istringstream ss(s);

		m = 0;
		while (ss >> x[m]) 
		{
			for (int i = 0; i < m; i++) 
				if (x[m] == x[i])
				{
					m--;
					break;
				}
			m++;
		}

		for (int i = 0; i < m; i++)
			for (int j = i+1; j < m; j++)
				if (x[i].size() < x[j].size())
				{
					string temp = x[i];
					x[i] = x[j];
					x[j] = temp;
				}

		found = -1;

		for (int j = 0; j < m; j++)
		{
			xx[j].clear();
			for (int i = 0; i < n; i++)
				if (matched(x[j], dict[i])) xx[j].push_back(dict[i]);

			if (xx[j].size() == 0){
				found = 0;
				break;
			}
		}
	
		string perm;
		if (found != 0) 
			perm = attempt(0, empty);

		istringstream oo(origin);

		m = 0;
		while (oo >> x[m]) m++;
			
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < (int) x[i].size(); j++) cout << perm[x[i][j]-'a'];
			if (i < m-1) cout << " ";
			else cout << endl;
		}
	}

	return 0;
}
